/*
 *说明：资源账号密码链 首页脚本
 *
 *@author mlc 2013-01-30
*/

var indexForm;
var grid;
var authRepeat;

$(function(){

	indexForm = $('#opeForm');
	authRepeat = $('#authRepeat').val();

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

		    {title:'节点名称',field:'node_decode',align:'center',width:80},
		    
		    {title:'资源组',field:'rsc_grp_name',align:'center',width:80},
				    
		    {title:'资源名称',field:'rsc_name',align:'center',width:80},
				    
			{title:'资源账号',field:'rsc_acc',align:'center',width:60},
			
			{title:'资源账号类型',field:'rsc_acc_type_decode',align:'center',width:60},
			
			{title:'资源账号状态',field:'rsc_acc_status_decode',align:'center',width:60},

            {title:'密码',field:'password_decode',align:'center',width:80}
        ]],
		pagination:true,
		singleSelect: false
	});

	if(authRepeat == '1'){
		queryOperation();
	}

	$('#queryBtn').click(showAuthRepeat);
	$('#downloadBtn').click(showDownloadBtn);
	
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
});

//翻页时自动调用此函数
function onLoadPrev(msg){

	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = indexForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'C_ACC_PWD_HIS!showC_ACC_PWD_HISList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

function showAuthRepeat(){
	if($('#authRepeat').val() != '1' ){
		var href = 'C_ACC_PWD_HIS!showAuthRepeat.do';
		//showSystemProccessing();
		openWin(href,'pop', 'A0', '450', '300');
	}else{
		queryOperation();
	}
}

//下载资源账号密码链（全部下载）
function showDownloadBtn() {
	$('#downloadBtn').attr('href', 'C_ACC_PWD_HIS!doDownload.do');
}

//清空操作（重置）
function clearOperation() {
	$('#authRepeat').val('0');
	indexForm.resetForm();
}

//查看明细
function showInfo(fid) {
	var href = 'C_ACC_PWD_HIS!showInfo.do?model.key=' + fid;
	openWin(href,'pop',editWindowWidth,editWindowHeight); 
}

//添加资源账号密码链
function addOperation(){  
	var href = 'C_ACC_PWD_HIS!showAdd.do';
	openWin(href,'pop');
}

//编辑资源账号密码链
function editOperation(){  

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}

	var href = 'C_ACC_PWD_HIS!showEdit.do?id=' + rows[0].key;
	openWin(href,'pop');
}   

//删除资源账号密码链
function deleteOperation() {

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];

	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}

	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'C_ACC_PWD_HIS!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//选择资源组
function select_c_rsc_grp() {
	var node_id = $('#node_id').val();
	var action = "C_RSC_GRP!showSelect.do?model.node_id="+node_id+"&model.rsc_grp_status=01";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_grp_id').val(row.rsc_grp_id);
		$('#rsc_grp_name').val(row.rsc_grp_name);
	}
}

//选择资源
function select_c_rsc() {
	var node_id = $('#node_id').val();
	var action = "C_RSC!showSelect.do?model.node_id="+node_id+"&model.rsc_status=01";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_id').val(row.rsc_id);
		$('#rsc_name').val(row.rsc_name);
	}
}

//操作成功后刷新列表
function afterOK(){

	queryOperation();
}